package com.cn.项目.飞机预约管理系统.chat;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class ChatPanel extends Mypanel2 implements ActionListener {
    //南边的图形界面
    //文本框：输入聊天内容
    protected JTextField southField;
    //发送按钮：发送聊天内容
    protected JButton sendButton;
    //"离线"按钮 断开连接
    protected JButton exitButton;
    //昵称
    protected  String nickname="我们";
    //初始化面板中的图形组件
    public ChatPanel() {
        super(1);
        labels[0].setText("输入昵称");
        promptLabel.setText("单击\"确定\"按钮,若服务器和客户连接上后，可开始聊天！");
        //北 确定按钮监听
        doTask1.addActionListener(this);
        //为南边的“发送”按钮添加监听
        sendButton.addActionListener(this);
        //南边离线监听
        exitButton.addActionListener(this);
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        if (e.getSource()==doTask1){
            doTask1Button();
        }

        if (e.getSource()==sendButton){
            sendButton();
        }

        if (e.getSource()==exitButton){
            exitButton();
        }


    }
    //只提供空方法，由子类继承
    protected void doTask1Button(){
    }
    protected void sendButton(){

    }
    protected void exitButton(){}

    //覆盖父类同名方法，重新绘制聊天室的GUI
    protected JPanel setSouthPanel(){
        JPanel southPanel = new JPanel();
        southField = new JTextField(20);
        southPanel.add(southField);
        //发送
        sendButton = new JButton("发送");
        //初始设置为不可用
        sendButton.setEnabled(false);
        southPanel.add(sendButton);
        //离线
        exitButton = new JButton("离线");
        //初始设置为不可用
        exitButton.setEnabled(false);
        southPanel.add(exitButton);

        return southPanel;
    }


    public static void main(String[] args) {
        JFrame app = new JFrame("聊天界面");
        app.getContentPane().add(new ChatPanel());
        app.setSize(400,300 );
        app.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        app.setVisible(true);

    }

}
